
//-------------------------
// Legislators as Lobbyists
// TABLE A13
//-------------------------


clear
use legislator_fe.dta

encode state, gen(state2)
by state county, sort: gen countyid = 1 if _n == 1
replace countyid = sum(countyid)

// generate demographic variables 

gen senior = (pop65to74 + pop75to84 + popover85)/population
gen whiteratio = white/population
gen blackratio = black/population
gen a1 = white/population
gen a2 = black/population
gen a3 = native/population 
gen a4 = asian/population
gen a5 = pacific/population
gen a6 = otherrace/population 
gen a7 = twomorerace/population
gen ethnic = 1 - (a1^2 + a2^2 + a3^2 + a4^2 + a5^2 + a6^2 + a7^2)
gen nohs = lessthanhs/pop_over25
gen hs = highschool/pop_over25 
gen loweredu = nohs + hs
gen college = bachelor/pop_over25
gen advanced = (master + professional + doctoral)/pop_over25
gen unemployment = pop_unemployed/pop_civilian


// generate contact variables 

gen housetotal = houcontact_s + houcontact_m
gen senatetotal = sencontact_s + sencontact_m
gen housetotal_t = houcontact_s_t + houcontact_m_t
gen senatetotal_t = sencontact_s_t + sencontact_m_t

gen puredolcontact_h = housetotal - housetotal_t 
gen puredolcontact_s = senatetotal - senatetotal_t


// generate interaction terms 


gen majority_h = .
replace majority_h = 1 if housedem == 0 & year == 2005
replace majority_h = 1 if housedem == 0 & year == 2006
replace majority_h = 1 if housedem == 1 & year == 2007
replace majority_h = 1 if housedem == 1 & year == 2008
replace majority_h = 1 if housedem == 1 & year == 2009
replace majority_h = 1 if housedem == 1 & year == 2010
replace majority_h = 1 if housedem == 0 & year == 2011
replace majority_h = 1 if housedem == 0 & year == 2012
replace majority_h = 0 if majority_h == .

gen majority_s = .
replace majority_s = 1 if sendem !=2 & year == 2005
replace majority_s = 1 if sendem !=2 & year == 2006
replace majority_s = 1 if sendem != 0 & year == 2007
replace majority_s = 1 if sendem != 0 & year == 2008
replace majority_s = 1 if sendem != 0 & year == 2009
replace majority_s = 1 if sendem != 0 & year == 2010
replace majority_s = 1 if sendem != 0 & year == 2011
replace majority_s = 1 if sendem != 0 & year == 2012
replace majority_s = 0 if majority_s == .

gen pres_party = .
replace pres_party = 1 if housedem == 0 & year == 2005
replace pres_party = 1 if housedem == 0 & year == 2006
replace pres_party = 1 if housedem == 0 & year == 2007
replace pres_party = 1 if housedem == 0 & year == 2008
replace pres_party = 1 if housedem == 1 & year == 2009
replace pres_party = 1 if housedem == 1 & year == 2010
replace pres_party = 1 if housedem == 1 & year == 2011
replace pres_party = 1 if housedem == 1 & year == 2012
replace pres_party = 0 if pres_party ==.


gen pres_party_s = .
replace pres_party_s = 1 if sendem != 2 & year == 2005
replace pres_party_s = 1 if sendem != 2 & year == 2006
replace pres_party_s = 1 if sendem != 2 & year == 2007
replace pres_party_s = 1 if sendem != 2 & year == 2008
replace pres_party_s = 1 if sendem != 0 & year == 2009
replace pres_party_s = 1 if sendem != 0 & year == 2010
replace pres_party_s = 1 if sendem != 0 & year == 2011
replace pres_party_s = 1 if sendem != 0 & year == 2012
replace pres_party_s = 0 if pres_party_s ==.


gen house_taa_dummy = 1 if housetotal_t  > 0
replace house_taa_dummy = 0 if housetotal_t == 0
gen senate_taa_dummy = 1 if senatetotal_t  > 0
replace senate_taa_dummy = 0 if senatetotal_t == 0

gen est = 0
replace est = 1 if estnoworkers !=.


by state dist, sort: gen newid = 1 if _n == 1
replace newid = sum(newid) 


replace pubunionmember_m = pubunionmember if pubunionmember_m  ==.
replace pubunionmember_m = pubunionmember_m /100

gen lnestnoworkers = ln(estnoworkers +1)

replace estnoworkers = estnoworkers/1000

gen countrymention = 0
replace countrymention = 1 if country !=""

gen indirect = (housetotal_t + senatetotal_t) - directmembercontact
replace indirect = 0 if indirect < 0


gen directdummy = .
replace directdummy = 1 if directmembercontact > 0
replace directdummy = 0 if directmembercontact == 0

macro define member_char "leadership_sen sjuris leadership_hou hjuris happrocom sapprocom sendem housedem majority_h majority_s pres_party pres_party_s"
macro define district_char1 "lnestnoworkers countrymention worker_pet l_manu_emp change_manuf senior whiteratio loweredu unemployment pubunionmember_m"
macro define district_char2 "countrymention worker_pet l_manu_emp change_manuf senior whiteratio loweredu unemployment pubunionmember_m"

* Regression 
 
eststo clear
eststo: quietly reg  certified directmembercontact, vce(cluster icpsr) 
eststo: quietly areg certified directmembercontact indirect puredolcontact_h puredolcontact_s $member_char $district_char2 i.year i.sic2, a(icpsr) vce(cluster icpsr)
eststo: quietly areg certified directdummy indirect puredolcontact_h puredolcontact_s $member_char $district_char2 i.year i.sic2, a(icpsr) vce(cluster icpsr)
eststo: quietly areg certified directdummy indirect puredolcontact_h puredolcontact_s $member_char $district_char1 i.year i.sic2, a(icpsr) vce(cluster icpsr)
esttab, star(* 0.10 ** 0.05 *** 0.01) drop(*sic2*) ar2
